package authority.dao;

import authority.comm.Lay;
import authority.entity.Dept;
import authority.util.DbBuilder;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 部门操作数据库
 */
public class DeptDao {

    public List<Dept> queryDept(Lay lay,Dept dept){
        StringBuffer sb=new StringBuffer();
        List<Object> l=new ArrayList<Object>();
        sb.append("select *,create_time createTime,update_time updateTime from dept where 1=1");
        sb.append(" limit ?,?");
        l.add((lay.getPage()-1)*lay.getLimit());
        l.add(lay.getLimit());
        return DbBuilder.getListBean(sb.toString(),Dept.class,l.toArray());
    }

    public Integer countDept(Dept dept){
        StringBuffer sb=new StringBuffer();
        List<Object> l=new ArrayList<Object>();
        sb.append("select count(*) from dept where 1=1");
        return DbBuilder.getCount(sb.toString());
    }

    public Integer addDept(Dept dept){
        StringBuffer sb=new StringBuffer();
        List<Object> l=new ArrayList<Object>();
        sb.append("insert into dept values(?,?,?,?,?,?,?)");
        l.add(dept.getId());
        l.add(dept.getName());
        l.add(dept.getOper());
        l.add(dept.getDetail());
        l.add(1);
        l.add(new Date());
        l.add(new Date());
        return DbBuilder.save(sb.toString(),l.toArray());
    }
}
